<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    private $_acl = null;
    private $_pegawai = null;


    protected function _initAutoload()
    {
        date_default_timezone_set('Asia/Jakarta');
        
        $loader = new Zend_Application_Module_Autoloader(array(
                        'namespace' => '',
                        'basePath' => APPLICATION_PATH
        ));
        
        Zend_Session::start();
        
        if(Zend_Auth::getInstance()->hasIdentity()) {
            Zend_Registry::set ('role', Zend_Auth::getInstance ()->getStorage ()->read ()->id_hak_akses);
            Zend_Registry::set ('id_pegawai', Zend_Auth::getInstance ()->getStorage ()->read ()->id_pegawai);
        }
        else
            Zend_Registry::set ('role', '5');
        
        $this->_acl = new Application_Model_AventurineAcl;

        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Application_Plugin_AccessCheck($this->_acl));
        
        return $loader;
    }

    protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        
        ZendX_JQuery::enableView($view);
        
        
        $view->headTitle('Aplikasi Manajerial : PT Aventurine Prana Asia');
        $view->headTitle()->setSeparator(' - ');
        $view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
                         ->appendName('description', 'Aplikasi Manajerial PT Aventurine');
        
        $view->doctype('HTML5');
        
        $navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
        $navConfig = new Zend_Navigation($navContainerConfig);
        
        $navtopContainerConfig = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','top');
        $navtopConfig = new Zend_Navigation($navtopContainerConfig);
        
        $role = Zend_Registry::get('role');
        
        if ($role == 1)
        {
            $role = '1';
        } elseif ($role == 2)
        {
            $role = '2';
        } elseif ($role == 5)
        {
            $role = '5';
        }
        
        $view->navigation()->setAcl($this->_acl)->setRole($role);
        $this->view->nav1 = $navConfig ;
        $this->view->nav2 = $navtopConfig;
        
    }
    
    protected function _initUsername()
    {
        
    }
}
